package org.cjstudio.messageboard;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.cjstudio.messageboard.MessageCommands.MessageCommand;
import org.cjstudio.messageboard.model.Message;

@SuppressWarnings("serial")
public class MessageBoardServlet extends HttpServlet {

	// Retrieve My Messages
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {

		@SuppressWarnings("rawtypes")
		MessageCommand messageCommand = MessageCommands.getCommand(MessageCommands.OPCODE_RETRIEVE_ALL);
		@SuppressWarnings("unchecked")
		ArrayList<Message> messageList = (ArrayList<Message>) messageCommand.execute();
		req.setAttribute("messageList", messageList);
		
		/* Change this part by using REDIRECT!! */
		RequestDispatcher view = req.getRequestDispatcher("MessageBoard.jsp");
		view.forward(req, resp);
	}
}